Skip to content

Slack sink replies to a thread with holmes analysis#1799

Closed
itisallgood wants to merge 17 commits into
masterfrom
rob-944-channel-override
Closed

Slack sink replies to a thread with holmes analysis#1799
itisallgood wants to merge 17 commits into
masterfrom
rob-944-channel-override

Conversation

@itisallgood
Copy link
Copy Markdown
Contributor

@itisallgood itisallgood commented May 5, 2025

Summary by CodeRabbit

  • New Features
    • Added support for passing Slack thread and channel context through actions, enabling more precise message threading and context in Slack notifications.
  • Documentation
    • Updated documentation links in configuration comments to point to new locations in the official documentation.
  • Style
    • Minor whitespace and formatting improvements for code readability.

@itisallgood itisallgood requested a review from moshemorad May 13, 2025 06:37
@moshemorad
Copy link
Copy Markdown
Contributor

@coderabbitai please review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

I'll review the pull request for you, but first I need to gather some information about it to provide a meaningful review.


🏁 Script executed:

#!/bin/bash
# Get PR details
gh pr view 1799 --repo robusta-dev/robusta

# Get PR files changed
gh pr view 1799 --repo robusta-dev/robusta --files

# Get the diff for review
gh pr diff 1799 --repo robusta-dev/robusta

Length of output: 9574


@moshemorad moshemorad closed this May 14, 2025
@moshemorad moshemorad reopened this May 14, 2025
@moshemorad
Copy link
Copy Markdown
Contributor

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2025

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2025

Walkthrough

The changes introduce a mechanism for propagating Slack thread and channel context through the action request and reporting pipeline. This is achieved by adding new context fields and classes, updating models, and modifying methods to handle and utilize this context. Documentation URLs in the Helm chart were also updated.

Changes

File(s) Change Summary
helm/robusta/values.yaml Updated documentation comment URLs for globalConfig and alertRelabel to new documentation locations. No functional changes.
src/robusta/core/model/base_params.py Added optional robusta_context dictionary attribute to HolmesParams class for passing internal context (e.g., Slack thread timestamp).
src/robusta/core/playbooks/internal/ai_integration.py Modified ask_holmes to copy thread_ts and channel_id from params.robusta_context to finding.robusta_context if present, before adding the finding to the event.
src/robusta/core/reporting/base.py Added robusta_context dictionary attribute to Finding class, initialized as an empty dict in the constructor.
src/robusta/core/reporting/callbacks.py Added a blank line before the return statement in ExternalActionRequestBuilder.create_for_func. No logic changes.
src/robusta/integrations/receiver.py Introduced SlackContainer model with channel_id and message_ts. Added optional slack_container fields to SlackExternalActionRequest and SlackActionsMessage. Updated methods to propagate robusta_context with Slack thread and channel info through action parameters when present.
src/robusta/integrations/slack/sender.py Added _resolve_slack_thread method to centralize Slack channel/thread resolution. Updated send_finding_to_slack to use this method and accept Optional[str] for thread_ts. Minor whitespace cleanup.

Sequence Diagram(s)

sequenceDiagram
    participant Slack as Slack (User)
    participant Receiver as Receiver
    participant Action as Action Handler
    participant Holmes as Holmes AI
    participant Finding as Finding
    participant Sender as SlackSender

    Slack->>Receiver: Sends Slack action with channel_id, message_ts
    Receiver->>Action: Calls __exec_external_request with action_params (includes robusta_context)
    Action->>Holmes: ask_holmes(params with robusta_context)
    Holmes->>Finding: Adds robusta_context to finding
    Finding->>Sender: send_finding_to_slack(finding with robusta_context)
    Sender->>Slack: Posts message to resolved channel/thread
Loading
sequenceDiagram
    participant User as User
    participant Receiver as Receiver
    participant Action as Action Handler

    User->>Receiver: Slack action (with slack_container)
    Receiver->>Action: __exec_external_request
    alt slack_container present
        Receiver->>Action: Add robusta_context to action_params (thread_ts, channel_id)
    end
    Action->>...: Process action with context
Loading

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da274fe and 997a9ce.

📒 Files selected for processing (1)
  • src/robusta/integrations/receiver.py (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: run_tests
  • GitHub Check: run_tests
🔇 Additional comments (5)
src/robusta/integrations/receiver.py (5)

52-55: Well-structured container model for Slack context.

This new Pydantic model clearly defines the structure needed to track Slack thread context (channel ID and message timestamp). This is a foundational piece that enables the thread reply functionality mentioned in the PR title.


61-61: Good extension of SlackExternalActionRequest.

This change appropriately extends the existing model with the new optional Slack container field, maintaining backward compatibility while adding the necessary context for thread replies.


82-82: Logical extension of SlackActionsMessage.

Adding the container field to SlackActionsMessage mirrors the pattern used for other Slack-related data, maintaining consistency in how Slack context is handled.


179-182: Effective propagation of thread context.

This implementation correctly extracts thread and channel information from the Slack container and adds it to the action parameters under a well-named "robusta_context" key. This follows the pattern established for other Slack parameters and enables downstream components to access this context.


252-252: Proper context propagation in _parse_slack_message.

This change ensures the Slack container context is propagated to each action's value, consistent with how other Slack fields are handled. This completes the context propagation chain needed for thread replies.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

thread_ts: Optional[str] = None,
) -> tuple[str, Optional[str]]:

channel = ChannelTransformer.template(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A. Any reason to call this if channel override was provided?
B. Not sure i fully understand how this will work if ChannelTransformer.template will work correctly if labels & annotations aren't pass in that flow.

[HolmesResultsBlock(holmes_result=holmes_result)], enrichment_type=EnrichmentType.ai_analysis
)

runner_context = getattr(params, "robusta_context", None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we are ignoring the sink param in this flow. It might cause issues with sending the finding to other sinks as well. I think we need to support the sink param in this flow as well.

Comment thread helm/robusta/values.yaml
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests

model: Optional[str]
# Additional internal context that helps runner to send investigation to appropriate sinks
# for now it is used only for passing thread_ts to slack sink internally;
robusta_context: Optional[Dict[str, Any]] = None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking here loud, we already have SlackCallbackParams which being used in other flows. I think it will be good idea to add relevant info there and reuse in relevant flows.
WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants